#include <bits/stdc++.h>
using namespace std;

struct FastIO {
	inline FastIO& operator >> (short& x) {
		x = 0;
		char f = 0, ch = getchar();
		while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
		while (ch <= '9' && ch >= '0') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
		return x = (f ? -x : x), *this;
	}
	inline FastIO& operator >> (int& x) {
		x = 0;
		char f = 0, ch = getchar();
		while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
		while (ch <= '9' && ch >= '0') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
		return x = (f ? -x : x), *this;
	}
	inline FastIO& operator >> (long long& x) {
		x = 0;
		char f = 0, ch = getchar();
		while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
		while (ch <= '9' && ch >= '0') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
		return x = (f ? -x : x), *this;
	}
	inline FastIO& operator >> (double& x) {
		x = 0;
		char f = 0, ch = getchar();
		double d = 0.1;
		while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
		while (ch <= '9' && ch >= '0') x = x * 10 + (ch ^ 48), ch = getchar();
		if (ch == '.') {
			ch = getchar();
			while (ch <= '9' && ch >= '0') x += d * (ch ^ 48), d *= 0.1, ch = getchar();
		}
		return x = (f ? -x : x), *this;
	}
} rin;

#define ll long long
#define uint unsigned int
#define reg register
#define ld long double
#define uint unsigned int
#define ull unsigned long long
#define qint const int&
#define qll const ll&
#define quint cosnt uint&
#define qull const ull&
#define endl "\n"

inline void qmod(int& x, const int& mod) {
	x = x >= mod? x - mod : x;
}

const int N = 1e4 + 10;
int n, k, ans, vis[N], timer, d[N], mx[N], mx2[N];
bool ok[N];
int ver[N << 1], nxt[N << 1], hd[N], nE;
inline void add(int u, int v) {
	ver[++nE] = v;
	nxt[nE] = hd[u];
	hd[u] = nE;
}
bool dfs(int u, int fa, int t) {
	if (t) {
		if (t != k) ok[u] = true;
	} else {
		if (ok[u] == true) return false;
		if (vis[u] == timer) return true;
		else {
			vis[u] = timer;
			return dfs(u, 0, k);
		}
	}
	bool flag = true;
	for (int e = hd[u]; ~e; e = nxt[e]) {
		int v = ver[e];
		if (v == fa) continue;
		flag &= dfs(v, u, t - 1);
	}
	return flag;
}
bool check(int u, int fa) {
	mx[u] = mx2[u] = 0;
	for (int e = hd[u]; ~e; e = nxt[e]) {
		int v = ver[e];
		if (v == fa) continue;
		if (check(v, u) == false) return false;
		if (mx[v] + 1 >= mx[u]) {
			mx2[u] = mx[u];
			mx[u] = mx[v] + 1;
		} else if (mx[v] + 1 > mx2[u]) mx2[u] = mx[v] + 1;
	}
	return mx[u] + mx2[u] + 1 < k;
}
bool chs[N];
bool chk(int u, int fa, int qwq, int t) {
	if (chs[u]) ++qwq;
	if (t == 1) return qwq == 1;
	for (int e = hd[u]; ~e; e = nxt[e]) {
		int v = ver[e];
		if (v == fa) continue;
		if (chk(v, u, qwq, t - 1) == false) return false;
	}
	return true;
}
signed main() {
//	freopen("life.in", "r", stdin);
//	freopen("life.out", "w", stdout);
	rin >> n >> k;
	memset(hd, -1, sizeof(hd));
	for (int i = 1; i <= n; ++i) vis[i] = n + 1;
	for (int i = 1, u, v; i < n; ++i) {
		rin >> u >> v, ++d[u], ++d[v];
		add(u, v), add(v, u);
	} 
	if ((*max_element(d + 1, d + n + 1)) <= 2) {
		cout << k << endl;
		return 0;
	} else if (n <= 18) {
		for (int p = 0; p < (1 << n); ++p) {
			for (int i = 1; i <= n; ++i) chs[i] = p >> (i - 1) & 1;
			bool flag = true;
			for (int i = 1; i <= n; ++i) flag &= chk(i, 0, 0, k);
			ans += flag;
		}
	} else {
		for (int i = 1; i <= n; ++i) {
			if (vis[i] == n + 1) {
		//			cout << i << endl;
				++timer;
				memset(ok, 0, sizeof(ok));
				ans += dfs(i, 0, k) && check(i, 0);
		//			cout << ans << endl;
			}
		}
	}
	if (ans) cout << "YES" << endl;
	else cout << "NO" << endl;
	cout << ans << endl;
	return 0;
}
